#!/bin/sh
# Moves Browser and Captive portal profiles to new location
OLD_BROWSER_PROFILE_PATH="$HOME/.mozilla/mozembed"
NEW_BROWSER_PROFILE_PATH="$HOME/.local/share/org.sailfishos/browser/.mozilla"

OLD_CAPTIVE_PORTAL_PROFILE_PATH="$HOME/.mozilla/captiveportal"
NEW_CAPTIVE_PORTAL_PROFILE_PATH="$HOME/.local/share/org.sailfishos/captiveportal/.mozilla"

if [ -e "$OLD_BROWSER_PROFILE_PATH/" ] && [ ! -e "$NEW_BROWSER_PROFILE_PATH/" ]
then
    rm -f $OLD_BROWSER_PROFILE_PATH/.parentlock
    mkdir -p "$NEW_BROWSER_PROFILE_PATH"
    if mv "$OLD_BROWSER_PROFILE_PATH/"* "$NEW_BROWSER_PROFILE_PATH/"
    then
        rmdir "$OLD_BROWSER_PROFILE_PATH"
    fi
fi

if [ -e "$OLD_CAPTIVE_PORTAL_PROFILE_PATH/" ] && [ ! -e "$NEW_CAPTIVE_PORTAL_PROFILE_PATH/" ]
then
    rm -f $OLD_CAPTIVE_PORTAL_PROFILE_PATH/.parentlock
    mkdir -p "$NEW_CAPTIVE_PORTAL_PROFILE_PATH"
    if mv "$OLD_CAPTIVE_PORTAL_PROFILE_PATH/"* "$NEW_CAPTIVE_PORTAL_PROFILE_PATH/"
    then
        rmdir "$OLD_CAPTIVE_PORTAL_PROFILE_PATH"
    fi
fi

exit 0
